# -*- coding: utf-8 -*-

from HTMLParser import HTMLParser
 
class PG(HTMLParser):
  def __init__(self):
    HTMLParser.__init__(self)
    self.title = 0
    self.t = ''
 
  def handle_starttag(self, tag, attrs):
    #print "Encountered the beginning of a %s tag" % tag
    #if tag == "a":
    #  if len(attrs) == 0: pass
    #  else:
    #    for (variable, value)  in attrs:
    #      if variable == "href":
    #        self.links.append(value)
    if tag == "title":
      self.title = 1
      if len(attrs) == 0: pass
      else:
        for (variable, value)  in attrs:
          pass
 
  def handle_data(self, text):
    if self.title:
      self.t = text
      self.title = 0

  def rt(self):
    return t

if __name__ == "__main__":
  html_code = """
  <a href="www.google.com"> google.com</a>
  <A Href="www.pythonclub.org"> PythonClub </a>
  <A HREF = "www.sina.com.cn"> Sina </a>
  <title>Wi-Fi</title>
  """
  hp = PG()
  hp.feed(html_code)
  hp.close()
  print hp.t

